#-*- coding: utf-8 -*-
#主成分分析 降维
import pandas as pd
from sklearn.decomposition import PCA

#参数初始化
inputfile = '../process_data/data/kaggle_bike_processed.csv'
outputfile = 'data/pca_dimention_reducted.csv' #降维后的数据

# 读入数据
dataSet = pd.read_csv(inputfile, header=0) #读入数据

# 得到训练数据和目标值
target = dataSet['count'].values
data = dataSet.drop(['count'], axis=1).values



pca = PCA(n_components=3)
pca.fit(data)
# print(pca.components_) #返回模型的各个特征向量
# print()
var = pca.explained_variance_ratio_
print(var) #返回各个成分各自的方差百分比
print()
#
print(sum(var[:3]))
#
# v = pca.explained_variance_  # 返回个成分的方差
# print(v)
# print()

low_d = pca.transform(data)
print(low_d)
print()
# print(pca.inverse_transform(low_d))
# print()

pd.DataFrame(low_d).to_csv(outputfile, index=0, header=0, float_format="%0.4f")


